home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / CodeWarrior Lite / Metrowerks C⁄C++ Lite / Headers / Universal Headers 2.0.1f / DatabaseAccess.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-22  |  12.2 KB  |  323 lines  |  [TEXT/MMCC]

  1. /*
  2.      File:        DatabaseAccess.h
  3.  
  4.      Contains:    Database Access Manager Interfaces.
  5.  
  6.      Version:    Technology:    System 7.5
  7.                  Package:    Universal Interfaces 2.0 in “MPW Latest” on ETO #17
  8.  
  9.      Copyright:    © 1984-1995 by Apple Computer, Inc.
  10.                  All rights reserved.
  11.  
  12.      Bugs?:        If you find a problem with this file, use the Apple Bug Reporter
  13.                  stack.  Include the file and version information (from above)
  14.                  in the problem description and send to:
  15.                      Internet:    apple.bugs@applelink.apple.com
  16.                      AppleLink:    APPLE.BUGS
  17.  
  18. */
  19.  
  20. #ifndef __DATABASEACCESS__
  21. #define __DATABASEACCESS__
  22.  
  23.  
  24. #ifndef __RESOURCES__
  25. #include <Resources.h>
  26. #endif
  27. /*    #include <Types.h>                                            */
  28. /*        #include <ConditionalMacros.h>                            */
  29. /*    #include <MixedMode.h>                                        */
  30. /*    #include <Files.h>                                            */
  31. /*        #include <OSUtils.h>                                    */
  32. /*            #include <Memory.h>                                    */
  33.  
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37.  
  38. #if PRAGMA_ALIGN_SUPPORTED
  39. #pragma options align=mac68k
  40. #endif
  41.  
  42. #if PRAGMA_IMPORT_SUPPORTED
  43. #pragma import on
  44. #endif
  45.  
  46.  
  47. enum {
  48.     typeNone                    = 'none',
  49.     typeDate                    = 'date',
  50.     typeTime                    = 'time',
  51.     typeTimeStamp                = 'tims',
  52.     typeDecimal                    = 'deci',
  53.     typeMoney                    = 'mone',
  54.     typeVChar                    = 'vcha',
  55.     typeVBin                    = 'vbin',
  56.     typeLChar                    = 'lcha',
  57.     typeLBin                    = 'lbin',
  58.     typeDiscard                    = 'disc',
  59. /* "dummy" types for DBResultsToText */
  60.     typeUnknown                    = 'unkn',
  61.     typeColBreak                = 'colb',
  62.     typeRowBreak                = 'rowb',
  63. /* pass this in to DBGetItem for any data type */
  64.     typeAnyType                    = 0
  65. };
  66.  
  67. /* infinite timeout value for DBGetItem */
  68. enum {
  69. /* messages for status functions for DBStartQuery */
  70.     kDBUpdateWind                = 0,
  71.     kDBAboutToInit                = 1,
  72.     kDBInitComplete                = 2,
  73.     kDBSendComplete                = 3,
  74.     kDBExecComplete                = 4,
  75.     kDBStartQueryComplete        = 5
  76. };
  77.  
  78. enum {
  79. /* messages for status functions for DBGetQueryResults */
  80.     kDBGetItemComplete            = 6,
  81.     kDBGetQueryResultsComplete    = 7,
  82.     kDBWaitForever                = -1,
  83. /*  flags for DBGetItem  */
  84.     kDBLastColFlag                = 0x0001,
  85.     kDBNullFlag                    = 0x0004
  86. };
  87.  
  88. typedef OSType DBType;
  89.  
  90. typedef struct DBAsyncParamBlockRec DBAsyncParamBlockRec, *DBAsyncParmBlkPtr;
  91.  
  92. /*
  93.         DBCompletionProcPtr uses register based parameters on the 68k and cannot
  94.         be written in or called from a high-level language without the help of
  95.         mixed mode or assembly glue.
  96.  
  97.             typedef pascal void (*DBCompletionProcPtr)(DBAsyncParmBlkPtr pb);
  98.  
  99.         In:
  100.          => pb              A1.L
  101. */
  102.  
  103. #if GENERATINGCFM
  104. typedef UniversalProcPtr DBCompletionUPP;
  105. #else
  106. typedef Register68kProcPtr DBCompletionUPP;
  107. #endif
  108.  
  109. struct DBAsyncParamBlockRec {
  110.     DBCompletionUPP                    completionProc;                /* pointer to completion routine */
  111.     OSErr                            result;                        /* result of call */
  112.     long                            userRef;                    /* for application's use */
  113.     long                            ddevRef;                    /* for ddev's use */
  114.     long                            reserved;                    /* for internal use */
  115. };
  116. enum {
  117.     uppDBCompletionProcInfo = kRegisterBased
  118.          | REGISTER_ROUTINE_PARAMETER(1, kRegisterA1, SIZE_CODE(sizeof(DBAsyncParmBlkPtr)))
  119. };
  120.  
  121. #if GENERATINGCFM
  122. #define CallDBCompletionProc(userRoutine, pb)        \
  123.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppDBCompletionProcInfo, (pb))
  124. #else
  125. /* (*DBCompletionProcPtr) cannot be called from a high-level language without the Mixed Mode Manager */
  126. #endif
  127.  
  128. #if GENERATINGCFM
  129. #define NewDBCompletionProc(userRoutine)        \
  130.         (DBCompletionUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppDBCompletionProcInfo, GetCurrentArchitecture())
  131. #else
  132. #define NewDBCompletionProc(userRoutine)        \
  133.         ((DBCompletionUPP) (userRoutine))
  134. #endif
  135.  
  136. struct ResListElem {
  137.     ResType                            theType;                    /* resource type */
  138.     short                            id;                            /* resource id */
  139. };
  140. typedef struct ResListElem ResListElem;
  141.  
  142. typedef ResListElem *ResListPtr, **ResListHandle;
  143.  
  144. /* structure for query list in QueryRecord */
  145. typedef Handle QueryArray[256];
  146.  
  147. typedef Handle **QueryListHandle;
  148.  
  149. struct QueryRecord {
  150.     short                            version;                    /* version */
  151.     short                            id;                            /* id of 'qrsc' this came from */
  152.     Handle                            queryProc;                    /* handle to query def proc */
  153.     Str63                            ddevName;                    /* ddev name */
  154.     Str255                            host;                        /* host name */
  155.     Str255                            user;                        /* user name */
  156.     Str255                            password;                    /* password */
  157.     Str255                            connStr;                    /* connection string */
  158.     short                            currQuery;                    /* index of current query */
  159.     short                            numQueries;                    /* number of queries in list */
  160.     QueryListHandle                    queryList;                    /* handle to array of handles to text */
  161.     short                            numRes;                        /* number of resources in list */
  162.     ResListHandle                    resList;                    /* handle to array of resource list elements */
  163.     Handle                            dataHandle;                    /* for use by query def proc */
  164.     long                            refCon;                        /* for use by application */
  165. };
  166. typedef struct QueryRecord QueryRecord;
  167.  
  168. typedef QueryRecord *QueryPtr, **QueryHandle;
  169.  
  170. /* structure of column types array in ResultsRecord */
  171. typedef DBType ColTypesArray[256];
  172.  
  173. typedef Handle ColTypesHandle;
  174.  
  175. struct DBColInfoRecord {
  176.     short                            len;
  177.     short                            places;
  178.     short                            flags;
  179. };
  180. typedef struct DBColInfoRecord DBColInfoRecord;
  181.  
  182. typedef DBColInfoRecord ColInfoArray[256];
  183.  
  184. typedef Handle ColInfoHandle;
  185.  
  186. struct ResultsRecord {
  187.     short                            numRows;                    /* number of rows in result */
  188.     short                            numCols;                    /* number of columns per row */
  189.     ColTypesHandle                    colTypes;                    /* data type array */
  190.     Handle                            colData;                    /* actual results */
  191.     ColInfoHandle                    colInfo;                    /* DBColInfoRecord array */
  192. };
  193. typedef struct ResultsRecord ResultsRecord;
  194.  
  195. typedef pascal OSErr (*DBQueryDefProcPtr)(long *sessID, QueryHandle query);
  196. typedef pascal Boolean (*DBStatusProcPtr)(short message, OSErr result, short dataLen, short dataPlaces, short dataFlags, DBType dataType, Ptr dataPtr);
  197. typedef pascal OSErr (*DBResultHandlerProcPtr)(DBType dataType, short theLen, short thePlaces, short theFlags, Ptr theData, Handle theText);
  198.  
  199. #if GENERATINGCFM
  200. typedef UniversalProcPtr DBQueryDefUPP;
  201. typedef UniversalProcPtr DBStatusUPP;
  202. typedef UniversalProcPtr DBResultHandlerUPP;
  203. #else
  204. typedef DBQueryDefProcPtr DBQueryDefUPP;
  205. typedef DBStatusProcPtr DBStatusUPP;
  206. typedef DBResultHandlerProcPtr DBResultHandlerUPP;
  207. #endif
  208.  
  209. enum {
  210.     uppDBQueryDefProcInfo = kPascalStackBased
  211.          | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  212.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(long*)))
  213.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(QueryHandle))),
  214.     uppDBStatusProcInfo = kPascalStackBased
  215.          | RESULT_SIZE(SIZE_CODE(sizeof(Boolean)))
  216.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(short)))
  217.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(OSErr)))
  218.          | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(short)))
  219.          | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(short)))
  220.          | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(short)))
  221.          | STACK_ROUTINE_PARAMETER(6, SIZE_CODE(sizeof(DBType)))
  222.          | STACK_ROUTINE_PARAMETER(7, SIZE_CODE(sizeof(Ptr))),
  223.     uppDBResultHandlerProcInfo = kPascalStackBased
  224.          | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  225.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DBType)))
  226.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(short)))
  227.          | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(short)))
  228.          | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(short)))
  229.          | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(Ptr)))
  230.          | STACK_ROUTINE_PARAMETER(6, SIZE_CODE(sizeof(Handle)))
  231. };
  232.  
  233. #if GENERATINGCFM
  234. #define NewDBQueryDefProc(userRoutine)        \
  235.         (DBQueryDefUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppDBQueryDefProcInfo, GetCurrentArchitecture())
  236. #define NewDBStatusProc(userRoutine)        \
  237.         (DBStatusUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppDBStatusProcInfo, GetCurrentArchitecture())
  238. #define NewDBResultHandlerProc(userRoutine)        \
  239.         (DBResultHandlerUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppDBResultHandlerProcInfo, GetCurrentArchitecture())
  240. #else
  241. #define NewDBQueryDefProc(userRoutine)        \
  242.         ((DBQueryDefUPP) (userRoutine))
  243. #define NewDBStatusProc(userRoutine)        \
  244.         ((DBStatusUPP) (userRoutine))
  245. #define NewDBResultHandlerProc(userRoutine)        \
  246.         ((DBResultHandlerUPP) (userRoutine))
  247. #endif
  248.  
  249. #if GENERATINGCFM
  250. #define CallDBQueryDefProc(userRoutine, sessID, query)        \
  251.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppDBQueryDefProcInfo, (sessID), (query))
  252. #define CallDBStatusProc(userRoutine, message, result, dataLen, dataPlaces, dataFlags, dataType, dataPtr)        \
  253.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppDBStatusProcInfo, (message), (result), (dataLen), (dataPlaces), (dataFlags), (dataType), (dataPtr))
  254. #define CallDBResultHandlerProc(userRoutine, dataType, theLen, thePlaces, theFlags, theData, theText)        \
  255.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppDBResultHandlerProcInfo, (dataType), (theLen), (thePlaces), (theFlags), (theData), (theText))
  256. #else
  257. #define CallDBQueryDefProc(userRoutine, sessID, query)        \
  258.         (*(userRoutine))((sessID), (query))
  259. #define CallDBStatusProc(userRoutine, message, result, dataLen, dataPlaces, dataFlags, dataType, dataPtr)        \
  260.         (*(userRoutine))((message), (result), (dataLen), (dataPlaces), (dataFlags), (dataType), (dataPtr))
  261. #define CallDBResultHandlerProc(userRoutine, dataType, theLen, thePlaces, theFlags, theData, theText)        \
  262.         (*(userRoutine))((dataType), (theLen), (thePlaces), (theFlags), (theData), (theText))
  263. #endif
  264.  
  265. extern pascal OSErr InitDBPack(void)
  266.  FIVEWORDINLINE(0x3F3C, 0x0004, 0x303C, 0x0100, 0xA82F);
  267. extern pascal OSErr DBInit(long *sessID, ConstStr63Param ddevName, ConstStr255Param host, ConstStr255Param user, ConstStr255Param passwd, ConstStr255Param connStr, DBAsyncParmBlkPtr asyncPB)
  268.  THREEWORDINLINE(0x303C, 0x0E02, 0xA82F);
  269. extern pascal OSErr DBEnd(long sessID, DBAsyncParmBlkPtr asyncPB)
  270.  THREEWORDINLINE(0x303C, 0x0403, 0xA82F);
  271. extern pascal OSErr DBGetConnInfo(long sessID, short sessNum, long *returnedID, long *version, Str63 ddevName, Str255 host, Str255 user, Str255 network, Str255 connStr, long *start, OSErr *state, DBAsyncParmBlkPtr asyncPB)
  272.  THREEWORDINLINE(0x303C, 0x1704, 0xA82F);
  273. extern pascal OSErr DBGetSessionNum(long sessID, short *sessNum, DBAsyncParmBlkPtr asyncPB)
  274.  THREEWORDINLINE(0x303C, 0x0605, 0xA82F);
  275. extern pascal OSErr DBSend(long sessID, Ptr text, short len, DBAsyncParmBlkPtr asyncPB)
  276.  THREEWORDINLINE(0x303C, 0x0706, 0xA82F);
  277. extern pascal OSErr DBSendItem(long sessID, DBType dataType, short len, short places, short flags, void *buffer, DBAsyncParmBlkPtr asyncPB)
  278.  THREEWORDINLINE(0x303C, 0x0B07, 0xA82F);
  279. extern pascal OSErr DBExec(long sessID, DBAsyncParmBlkPtr asyncPB)
  280.  THREEWORDINLINE(0x303C, 0x0408, 0xA82F);
  281. extern pascal OSErr DBState(long sessID, DBAsyncParmBlkPtr asyncPB)
  282.  THREEWORDINLINE(0x303C, 0x0409, 0xA82F);
  283. extern pascal OSErr DBGetErr(long sessID, long *err1, long *err2, Str255 item1, Str255 item2, Str255 errorMsg, DBAsyncParmBlkPtr asyncPB)
  284.  THREEWORDINLINE(0x303C, 0x0E0A, 0xA82F);
  285. extern pascal OSErr DBBreak(long sessID, Boolean abort, DBAsyncParmBlkPtr asyncPB)
  286.  THREEWORDINLINE(0x303C, 0x050B, 0xA82F);
  287. extern pascal OSErr DBGetItem(long sessID, long timeout, DBType *dataType, short *len, short *places, short *flags, void *buffer, DBAsyncParmBlkPtr asyncPB)
  288.  THREEWORDINLINE(0x303C, 0x100C, 0xA82F);
  289. extern pascal OSErr DBUnGetItem(long sessID, DBAsyncParmBlkPtr asyncPB)
  290.  THREEWORDINLINE(0x303C, 0x040D, 0xA82F);
  291. extern pascal OSErr DBKill(DBAsyncParmBlkPtr asyncPB)
  292.  THREEWORDINLINE(0x303C, 0x020E, 0xA82F);
  293. extern pascal OSErr DBGetNewQuery(short queryID, QueryHandle *query)
  294.  THREEWORDINLINE(0x303C, 0x030F, 0xA82F);
  295. extern pascal OSErr DBDisposeQuery(QueryHandle query)
  296.  THREEWORDINLINE(0x303C, 0x0210, 0xA82F);
  297. extern pascal OSErr DBStartQuery(long *sessID, QueryHandle query, DBStatusUPP statusProc, DBAsyncParmBlkPtr asyncPB)
  298.  THREEWORDINLINE(0x303C, 0x0811, 0xA82F);
  299. extern pascal OSErr DBGetQueryResults(long sessID, ResultsRecord *results, long timeout, DBStatusUPP statusProc, DBAsyncParmBlkPtr asyncPB)
  300.  THREEWORDINLINE(0x303C, 0x0A12, 0xA82F);
  301. extern pascal OSErr DBResultsToText(ResultsRecord *results, Handle *theText)
  302.  THREEWORDINLINE(0x303C, 0x0413, 0xA82F);
  303. extern pascal OSErr DBInstallResultHandler(DBType dataType, DBResultHandlerUPP theHandler, Boolean isSysHandler)
  304.  THREEWORDINLINE(0x303C, 0x0514, 0xA82F);
  305. extern pascal OSErr DBRemoveResultHandler(DBType dataType)
  306.  THREEWORDINLINE(0x303C, 0x0215, 0xA82F);
  307. extern pascal OSErr DBGetResultHandler(DBType dataType, DBResultHandlerUPP *theHandler, Boolean getSysHandler)
  308.  THREEWORDINLINE(0x303C, 0x0516, 0xA82F);
  309.  
  310. #if PRAGMA_IMPORT_SUPPORTED
  311. #pragma import off
  312. #endif
  313.  
  314. #if PRAGMA_ALIGN_SUPPORTED
  315. #pragma options align=reset
  316. #endif
  317.  
  318. #ifdef __cplusplus
  319. }
  320. #endif
  321.  
  322. #endif /* __DATABASEACCESS__ */
  323.